package br.com.tcc.systemdx.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import br.com.tcc.systemdx.commons.persistence.GenericEntity;

@MappedSuperclass
public abstract class BaseEntity implements Serializable, GenericEntity<Long> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6495119782957340744L;
	
	@Id
	@Column(name = "id", nullable = false)
	@GeneratedValue(strategy=GenerationType.AUTO)
	protected Long id;

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}
	
	@Override
	public final int hashCode() {
		if (id != null) {
			return id.hashCode();
		} else {
			return super.hashCode();
		}
	}
	
	@Override
	public final boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (obj instanceof BaseEntity) {
			BaseEntity newObj = (BaseEntity) obj;
			if (newObj.id != null && this.id != null) {
				return newObj.id.equals(this.id);
			}
		}
		return super.equals(obj);
	}

}
